package com.example.physicalexaminationsystem.controller;

import cn.hutool.json.JSONUtil;
import com.example.physicalexaminationsystem.dto.ResponseDto;
import com.example.physicalexaminationsystem.mapper.KnowledgeDao;
import com.example.physicalexaminationsystem.model.KnowledgeEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author shiwenzhuo
 * 
 * @description
 */
@RestController
@RequestMapping("/api/knowledge")
public class KnowledgeController {
    @Resource
    private KnowledgeDao knowledgeDao;

    //获取体检常识信息
    @RequestMapping("/getKnowledgeList")
    public ResponseDto getKnowledgeList() {
        return ResponseDto.success(knowledgeDao.selectList(null));
    }

    //添加体检常识信息
    @RequestMapping("/addKnowledge")
    public ResponseDto addKnowledge(@RequestBody Map<String, String> params) {
        KnowledgeEntity knowledgeEntity = JSONUtil.toBean(JSONUtil.parseObj(params), KnowledgeEntity.class);
        knowledgeDao.insert(knowledgeEntity);
        return ResponseDto.success();
    }

    //删除体检常识信息根据id
    @RequestMapping("/deleteKnowledgeById")
    public ResponseDto deleteKnowledgeById(@RequestParam Long id) {
        knowledgeDao.deleteById(id);
        return ResponseDto.success();
    }

    //修改体检常识信息
    @RequestMapping("/updateKnowledge")
    public ResponseDto updateKnowledge(@RequestBody Map<String, Object> params) {
        KnowledgeEntity knowledgeEntity = JSONUtil.toBean(JSONUtil.parseObj(params), KnowledgeEntity.class);
        knowledgeDao.updateById(knowledgeEntity);
        return ResponseDto.success();
    }
}
